﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.DependencyInjection;
using StyleMVVM.UnitTests.TestClasses.FuncFactory;
using StyleMVVM.UnitTests.TestClasses.SimpleObjects;

#if DOT_NET
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
#endif

namespace StyleMVVM.UnitTests.DependencyInjection
{
	[TestClass]
	public class FuncFactoryTests : BaseTestClass
	{
		[TestMethod]
		public void FuncImportTest()
		{
			ImportFuncFactory importFuncFactory = Container.Locate<ImportFuncFactory>();

			Assert.IsNotNull(importFuncFactory);

			SimpleExport simpleExport = importFuncFactory.ImportFunc();

			Assert.IsNotNull(simpleExport);
		}

		[TestMethod]
		public void FuncWithContextImportTest()
		{
			ImportFuncFactoryWithContext importFuncFactoryWithContext = Container.Locate<ImportFuncFactoryWithContext>();

			Assert.IsNotNull(importFuncFactoryWithContext);

			SimpleExport simpleExport = importFuncFactoryWithContext.ImportFunc(Container.CreateInjectionContext());

			Assert.IsNotNull(simpleExport);
		}

		[TestMethod]
		public void FuncWithContextAndParams()
		{
			ImportFuncFactoryWithContextAndParams importFuncFactory =
				Container.Locate<ImportFuncFactoryWithContextAndParams>();

			Assert.IsNotNull(importFuncFactory);

			ExportWithParams exportWithParams = importFuncFactory.ImportFunc(Container.CreateInjectionContext(),
																								  new object[] { 10 });

			Assert.IsNotNull(exportWithParams);
			Assert.AreEqual(10, exportWithParams.X);
		}

		[TestMethod]
		public void LocateFunc()
		{
			Func<SimpleExport> importMethod = Container.Locate<Func<SimpleExport>>();

			Assert.IsNotNull(importMethod);

			SimpleExport simpleExport = importMethod();

			Assert.IsNotNull(simpleExport);
		}

		[TestMethod]
		public void LocateFuncWithContext()
		{
			Func<IInjectionContext, SimpleExport> importMethod = Container.Locate<Func<IInjectionContext, SimpleExport>>();

			Assert.IsNotNull(importMethod);

			SimpleExport simpleExport = importMethod(Container.CreateInjectionContext());

			Assert.IsNotNull(simpleExport);
		}

		[TestMethod]
		public void LocateFuncWithContextAndParams()
		{
			Func<IInjectionContext, object[], ExportWithParams> importMethod = Container.Locate<Func<IInjectionContext, object[], ExportWithParams>>();

			Assert.IsNotNull(importMethod);

			ExportWithParams exportWithParams = importMethod(Container.CreateInjectionContext(), new object[]{ 10 });

			Assert.IsNotNull(exportWithParams);
			Assert.AreEqual(10, exportWithParams.X);
		}

		[TestMethod]
		public void LocateGenericFunc()
		{
			Func<IServiceTwo, ICompoundService> importMethod = Container.Locate<Func<IServiceTwo, ICompoundService>>();

			Assert.IsNotNull(importMethod);

			ICompoundService compoundService = importMethod(new ServiceTwo());

			Assert.IsNotNull(compoundService);
		}

		[TestMethod]
		public void ImportGenericFunc()
		{
			ImportFuncGeneric import = Container.Locate<ImportFuncGeneric>();

			Assert.IsNotNull(import);

			ICompoundService compoundService = import.CreateCompound(new ServiceTwo());

			Assert.IsNotNull(compoundService);
		}
	}
}
